package com.arnold.www.singleton;

/**
 * @ClassName Singleton_lazyLoading_doubleCheckLock
 * @Description: 懒汉式线程安全实现（双重校验锁）
 * @Author Arnold
 * @Date 2020/4/11
 * @Version V2.0
 **/
public class Singleton_lazyLoading_doubleCheckLock {
    //私有化构造方法
    private Singleton_lazyLoading_doubleCheckLock(){}

    //设置volatile,防止虚拟机的指令重排序导致其他锁
    private static volatile Singleton_lazyLoading_doubleCheckLock instance;

    //对外暴露获取实例方法
    public static  Singleton_lazyLoading_doubleCheckLock getInstance() {
        if (instance==null){
            synchronized(Singleton_lazyLoading_doubleCheckLock.class){
                if (instance==null){
                    instance = new Singleton_lazyLoading_doubleCheckLock();
                }
            }
        }
        return  instance;
    }
}